In order to produce a formatted string, both string.Create
and either FormattableString.Invariant
or
FormattableString.CurrentCulture
can be used. However, string.Create
rents array buffers from
ArrayPool<char>
making it more performant, as well as preventing unnecessary allocations and future stress on the Garbage
Collector.
This applies to .NET versions after .NET 6, when these string.Create
overloads were introduced.
What is the potential impact?
We measured a significant improvement both in execution time and memory allocation. For more details see the Benchmarks
section from
the More info
tab.